package com.itheima.cases_demo.string_times;

public class Test {
    public static void main(String[] args) {
        // 统计字符串拼接耗时
        long times = stringTime();
        System.out.println(times);

        long time2 = stringBuilderTime();
        System.out.println(time2);
    }
    
    public static long stringTime() {
        long start = System.currentTimeMillis();
        String str = "";
        for (int i = 0; i < 100000; i++) {
            str += "-";
        }
        long end = System.currentTimeMillis();
        return end - start;
    }

    public static long stringBuilderTime() {
        long start = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder("-");
        for (int i = 0; i < 100000; i++) {
            sb.append("-");
        }
        long end = System.currentTimeMillis();
        return end - start;
    }
}
